<?php 
	namespace Admin\Controller;
	use Think\Controller;

	class LunboController extends Controller
	{
		// 查看
		public function index()
		{
			$lunbo = M('lunbo');
			$list = $lunbo->select();
			$this->assign('list',$list);
			$this->display();
		}

	
		// 删除
		public function del()
		{
			$lunbo = M('lunbo');
												
			if($lunbo->delete(I()['id']) > 0){
				$this->success('轮播图删除成功',U('Lunbo/index'));
			}else{
				$this->error('轮播图删除失败');
			}
		}

		// 修改的内容
		public function edit()
		{	
			$id = I()['id'];
			$lunbo = M('lunbo');
			$edit = $lunbo->where("id=$id")->find();
			$this->assign('vo',$edit);
			$this->display();
		}

		// 执行修改的内容
		public function doedit()
		{
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->savePath  =      ''; // 设置附件上传目录
			// 上传文件 
			$info   =   $upload->upload();
			if(!$info) {// 上传错误提示错误信息    
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息    
				foreach($info as $file){        
					$photo=$file['savepath'].$file['savename'];
				}
			}

			$lunbo = M('lunbo');
			$data['photo'] = $photo;
			if($lunbo->save($data) > 0){
				$this->success('修改成功',U('Lunbo/index'));
			}else{
				$this->error('修改失败');
			}
		}

		// 文件上传
		public function upload()
		{ 
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->savePath  =      ''; // 设置附件上传目录
			// 上传文件 
			$info   =   $upload->upload();
			if(!$info) {// 上传错误提示错误信息    
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息    
				foreach($info as $file){        
					$photo=$file['savepath'].$file['savename'];
				}
			}

			// 执行添加
			$lunbo = M('lunbo');
			$data['photo'] = $photo;
			if($lunbo->add($data)){
				$this->success('图片添加成功',U('Lunbo/index'));
			}else{
				$this->error('图片添加失败');
			}
	    }



	}